package com.mutual.assistance.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mutual.assistance.system.converter.SystemConverterParams;
import com.mutual.assistance.system.mapper.DictionaryMapper;
import com.mutual.assistance.system.model.dto.DictionaryDTO;
import com.mutual.assistance.system.model.po.DictionaryPO;
import com.mutual.assistance.system.service.DictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenyuxin
 * @version 1.0
 * @description 数据字典实现类
 * @date 2023/4/24 17:14
 */
@Service
@Slf4j
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, DictionaryPO> implements DictionaryService {

    @Resource
    private SystemConverterParams systemConverterParams;

    @Override
    public List<DictionaryDTO> queryAll() {
        List<DictionaryPO> list = this.list();
        log.info("获取到数据字典信息：{}", list);
        return systemConverterParams.dictionaryPO2DictionaryDTOList(list);
    }

    @Override
    public DictionaryDTO getByCode(String code) {
        LambdaQueryWrapper<DictionaryPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DictionaryPO::getCode, code);
        DictionaryPO dictionaryPO = this.getOne(queryWrapper);
        log.info("获取到单条数据字典：{}", dictionaryPO);
        return systemConverterParams.dictionaryPO2DictionaryDTO(dictionaryPO);
    }
}
